{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Jupyter notebook to create many_cells in the same dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import (\n",
    "    \"fmt\"\n",
    "    \"os\"\n",
    ")\n",
    "\n",
    "(func() {\n",
    "    f, err := os.Create(\"many_cells.ipynb\")\n",
    "    if err != nil {\n",
    "        fmt.Printf(\"Failed to open: %v\\n\", err)\n",
    "    }\n",
    "    defer f.Close()\n",
    "    f.WriteString(`{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"# many cells\\n\",\n",
    "    \"This notebook demonstrates lgo can handle thousands of cells though lgo builds and loads shared objects file on every executions.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"import (\\n\",\n",
    "    \"    \\\"fmt\\\"\\n\",\n",
    "    \"    \\\"strings\\\"\\n\",\n",
    "    \"    \\\"time\\\"\\n\",\n",
    "    \")\\n\",\n",
    "    \"\\n\",\n",
    "    \"interval := 64\\n\",\n",
    "    \"start := time.Now()\\n\",\n",
    "    \"var sum int64\\n\",\n",
    "    \"var msgs []string\"\n",
    "   ]\n",
    "  },\n",
    "`)\n",
    "    for i := 1; i <= 1024; i++ {\n",
    "        f.WriteString(fmt.Sprintf(`{\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"{\\n\",\n",
    "    \"    n := %d\\n\",\n",
    "    \"    sum += int64(n)\\n\",\n",
    "    \"    if n %% interval == 0 {\\n\",\n",
    "    \"        end := time.Now()\\n\",\n",
    "    \"        msgs = append(\\n\",\n",
    "    \"            msgs,\\n\",\n",
    "    \"            fmt.Sprintf(\\\"cycle: [%%d, %%d], took %%v on average\\\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\\n\",\n",
    "    \"        start = end\\n\",\n",
    "    \"    }\\n\",\n",
    "    \"}\"\n",
    "   ]\n",
    "  },\n",
    "`, i))   \n",
    "    }\n",
    "    f.WriteString(`{\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"name\": \"stdout\",\n",
    "     \"output_type\": \"stream\",\n",
    "     \"text\": [\n",
    "      \"524800\\n\"\n",
    "     ]\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"sum\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"name\": \"stdout\",\n",
    "     \"output_type\": \"stream\",\n",
    "     \"text\": [\n",
    "      \"cycle: [1, 64], took 684.526294ms on average\\n\",\n",
    "      \"cycle: [65, 128], took 672.778457ms on average\\n\",\n",
    "      \"cycle: [129, 192], took 681.855261ms on average\\n\",\n",
    "      \"cycle: [193, 256], took 674.783885ms on average\\n\",\n",
    "      \"cycle: [257, 320], took 686.477005ms on average\\n\",\n",
    "      \"cycle: [321, 384], took 683.289412ms on average\\n\",\n",
    "      \"cycle: [385, 448], took 687.293805ms on average\\n\",\n",
    "      \"cycle: [449, 512], took 693.450195ms on average\\n\",\n",
    "      \"cycle: [513, 576], took 672.261078ms on average\\n\",\n",
    "      \"cycle: [577, 640], took 682.784516ms on average\\n\",\n",
    "      \"cycle: [641, 704], took 691.448044ms on average\\n\",\n",
    "      \"cycle: [705, 768], took 671.875065ms on average\\n\",\n",
    "      \"cycle: [769, 832], took 673.786842ms on average\\n\",\n",
    "      \"cycle: [833, 896], took 681.162642ms on average\\n\",\n",
    "      \"cycle: [897, 960], took 672.475553ms on average\\n\",\n",
    "      \"cycle: [961, 1024], took 680.732248ms on average\\n\",\n",
    "      \"765\\n\",\n",
    "      \"<nil>\\n\"\n",
    "     ]\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"fmt.Println(strings.Join(msgs, \\\"\\\\n\\\"))\"\n",
    "   ]\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {\n",
    "  \"kernelspec\": {\n",
    "   \"display_name\": \"Go (lgo)\",\n",
    "   \"language\": \"go\",\n",
    "   \"name\": \"lgo\"\n",
    "  },\n",
    "  \"language_info\": {\n",
    "   \"file_extension\": \"\",\n",
    "   \"mimetype\": \"\",\n",
    "   \"name\": \"go\",\n",
    "   \"version\": \"\"\n",
    "  }\n",
    " },\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 2\n",
    "}\n",
    "`)\n",
    "})()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go (lgo)",
   "language": "go",
   "name": "lgo"
  },
  "language_info": {
   "file_extension": "",
   "mimetype": "",
   "name": "go",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
